FROM centos:centos7
#RUN yum check-update
EXPOSE 8080 1883 61623

RUN yum -y install wget unzip

# Install Java 8
RUN wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.rpm" && rpm -ivh jdk-8u25-linux-x64.rpm

# Install HiveMQ
RUN cd /opt && wget --content-disposition http://www.hivemq.com/wp-content/uploads/hivemq-2.2.1.zip && unzip hivemq-2.2.1.zip
COPY configuration.properties /opt/hivemq-2.2.1/conf/configuration.properties
RUN ln -s /opt/hivemq-2.2.1 /opt/hivemq && useradd -d /opt/hivemq hivemq && chown -R hivemq.hivemq /opt/hivemq-2.2.1 && chown -R hivemq.hivemq /opt/hivemq && cd /opt/hivemq && chmod +x ./bin/run.sh

# Install SiteWhere
RUN cd /opt && wget --content-disposition https://s3.amazonaws.com/sitewhere/sitewhere-server-1.0.2.zip && unzip sitewhere-server-1.0.2.zip
ENV CATALINA_BASE="/opt/sitewhere-server-1.0.2" CATALINA_HOME="/opt/sitewhere-server-1.0.2"
COPY sitewhere-server-1.0.2.xml /opt/sitewhere-server-1.0.2/conf/sitewhere/sitewhere-server.xml
RUN ln -s /opt/sitewhere-server-1.0.2 /opt/sitewhere && useradd -d /opt/sitewhere sitewhere && chown -R sitewhere.sitewhere /opt/sitewhere-server-1.0.2 && chown -R sitewhere.sitewhere /opt/sitewhere && cd /opt/sitewhere && chmod +x /opt/sitewhere-server-1.0.2/bin/*.sh 
CMD nohup /opt/hivemq/bin/run.sh > /dev/null & nohup /opt/sitewhere/bin/startup.sh & echo 'Starting SiteWhere...' && while ! [ -f /opt/sitewhere/logs/catalina.out ]; do sleep 1; done && tail -f /opt/sitewhere/logs/catalina.out
